package ui.tools;

import java.awt.Point;

import javax.swing.JOptionPane;

import board.NodeLabel;
import board.SimpleMark;

import sgf.SGFParseException;
import ui.EditController;
import util.Util;

/**
 * EditTool for adding NodeLabels.
 * @author TKington
 *
 */
public class LabelTool extends EditTool {
	@Override
	public boolean mouseClicked(int x, int y, int modifiers) {
		EditController controller = EditController.instance();
		try {
			SimpleMark m = controller.getSimpleMark(x, y);
			if(m != null)
				controller.removeMark(m);
			
			if(!(m instanceof NodeLabel)) {
				String label = JOptionPane.showInputDialog(null, "Enter a label");
				if(label == null)
					return false;
				
				controller.addMark(new NodeLabel(label, new Point(x, y)));
			}
		}
		catch(SGFParseException e) {
			Util.log(e);
		}
		
		return true;
	}
}
